﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Ex03.GarageLogic
{
    /// <summary>
    /// abstract class which contain basic information which every Vehicle must have (m_VehicleModelName, m_VehicleLicenseNumber, m_WheelsArray, m_EnergySource, m_EnergyLeftInEnergySource)
    /// </summary>
    internal abstract class Vehicle
    {
        private readonly int r_NumberOfWheels = 0;
        private string m_VehicleModelName = string.Empty;
        private string m_VehicleLicenseNumber = string.Empty;
        private Wheel[] m_WheelsArray;
        private EnergySource m_EnergySource = null;
        private float m_EnergyLeftInEnergySource = 0;

        protected Vehicle(string i_VehicleModelName, string i_VehicleLicenseNumber, Wheel[] i_WheelsArary, EnergySource i_EnergySource)
        {
            m_VehicleModelName = i_VehicleModelName;
            m_VehicleLicenseNumber = i_VehicleLicenseNumber;
            m_WheelsArray = i_WheelsArary;
            r_NumberOfWheels = i_WheelsArary.Length;  
            m_EnergySource = i_EnergySource;
        }

        public string VehicleLicenseNumber
        {
            get { return m_VehicleLicenseNumber; }
            set { m_VehicleLicenseNumber = value; }
        }

        public Wheel[] WheelsArray
        {
            get { return m_WheelsArray; }     
        }

        public EnergySource EnergySource
        {
            get { return m_EnergySource; }          
        }

        public bool isPowerdBy(Type i_powerSource)
        {
            return i_powerSource == m_EnergySource.GetType();
        }

        /// <summary>
        /// Calculate the percentage of Energy Left In Energy Source
        /// </summary>
        public void CalculateEnergyLeftInEnergySource()
        {
            const float k_toPresentage = 100;
            m_EnergyLeftInEnergySource = (m_EnergySource.CurrentEnergy / m_EnergySource.MaxEnergy) * k_toPresentage;
        }

        /// <summary>
        /// Overriding <see cref="Object.ToString"/>
        /// </summary>
        /// <returns>string with Vehicle properties (m_VehicleLicenseNumber, m_VehicleModelName)</returns>
        public override string ToString()
        {
            int wheelCounter = 1;
            StringBuilder toString = new StringBuilder();
            string vehicleInfo = string.Format(@"
Lisencse Number: {0}
ModelName: {1}"
                , m_VehicleLicenseNumber
                , m_VehicleModelName);

            toString.AppendLine(vehicleInfo);
            foreach (Wheel whell in m_WheelsArray)
            {
                toString.AppendLine("Whell " + wheelCounter + ":");
                toString.AppendLine(whell.ToString());
                wheelCounter++;
            }

            toString.AppendLine(m_EnergySource.ToString());

            return toString.ToString();
        }

        /// <summary>
        /// every spicific type of vehicle have its own unice propertis which need to recive from the user
        /// </summary>
        /// <returns>list of strings with the requests for the unice propertis</returns>
        public abstract List<string> GetSpecificProperties();

        /// <summary>
        /// set the unice propertis to the specific vehicle
        /// </summary>
        /// <param name="i_ListOfSpecificVehiclePropertiesFromUser">list of valus to set to the specific vehicle</param>
        public abstract void SetSpecificProperties(List<string> i_ListOfSpecificVehiclePropertiesFromUser);

        /// <summary>
        /// make a string with a message and Enum names
        /// </summary>
        /// <param name="i_MessageStart">message to put in the return string before the Enum names</param>
        /// <param name="i_EnumProperty">the enum to get a string with its names</param>
        /// <returns>string with message and Enum names list</returns>
        protected string GetPropertyMessageOfEnum(string i_MessageStart, Type i_EnumProperty)
        {
            StringBuilder colorMessage = new StringBuilder();
            string[] names = Enum.GetNames(i_EnumProperty);

            colorMessage.AppendLine(i_MessageStart);
            foreach (string name in names)
            {
                colorMessage.AppendLine(name);
            }

            return colorMessage.ToString();
        }
    }
}